<?php

/**
 * A date picker.
 * 
 * This is based on the jQuery UI date picker.
 */
class DateField extends ExtendedFormInputLeaf {
	
	public function __construct($claimed_input) {
		parent::__construct(new TextField($claimed_input));
		$widget = $this->get_main()->get_js_elem();
		
		// TODO: Get a better way to do this kind of things
		$this->add('datapicker-start', "
			<script type='text/javascript'>
				$(function() {
					$widget.datepicker({
						showButtonPanel: true,
						changeMonth: true,
						changeYear: true,
						minDate: '-50Y',
						maxDate: '-12Y',
						dateFormat: 'dd/mm/yy'
					});
					$widget.datepicker('setDate', '");

		$this->c['initial_value'] = '-20Y';	
		
		$this->c['datapicker-end'] = "');
				});
			</script>
		";
		
		/*$date = "$widget.datepicker('getDate')";
		$this->add_check(new DateCheck());*/
	}
	
	public function set_initial_value($value) {
		$this->c['initial_value'] = date_to_slash_date_string($value);
	}
	
}

/*class DateCheck extends ClientSideCheck {
	
	public function comment($alias) {
		return '$alias is not a valid date. Please use the date picker to select a valid date.';
	}
	
	public function validate_js($value) { return "
		alert($value);
		return true;
	";}
	
}*/